// Copyright (C) ZHENG Zhong <heavyzheng nospam-at gmail D0T com>
//
// $Id: config_multi_dests.cpp 230 2008-09-15 15:50:18Z heavyzheng $
//

//! \example config_multi_dests.cpp
//!
//! This file implements the function for retrieving a named logger object. It ensures that before
//! any logger object is created, the log factory is well configured. In this example, the log
//! factory is configured to have two destinations: the console and a rolling file. Newly created
//! logger objects will have their thresholds set to debug level.

#include "config_multi_dests.hpp"

namespace zzheng {
namespace example {

    // This function configures the log factory before any logger object is created.
    logging::logger get_logger_to_multi_dests(const std::string& name) {
        static bool configured = false;
        if (!configured) {

            logging::log_factory& factory = logging::log_factory::instance();
            factory.set_threshold(logging::debug_level());

            logging::rolling_file dest_1;
            dest_1.set_dirname("${TMP}/zzheng")
                  .set_basename("dummy.log")
                  .set_max_file_size_kb(1024U)
                  .set_max_backup_index(100U);
            factory.add_destination("rolling_file", dest_1);

            logging::console dest_2;
            dest_2.set_use_stderr(true)
                  .set_immediate_flush(true);
            factory.add_destination("console", dest_2);

            factory.configure();
            configured = true;
        }
        return logging::get_logger(name);
    }

} // namespace zzheng::example
} // namespace zzheng



